<!doctype html>
<html lang="zh-CN" th:replace="admin-layout :: layout(~{::title}, ~{}, ~{::script}, ~{::body}, 'material-list')"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title th:text="${id}?'修改图片':_">添加图片</title>
    <script th:inline="javascript">
        $("#submitBtn").click(function(){
            var name=$("#name").val();
            if(!name){
                msgAlert("请输入图片名称")
                return;
            }
            var inputImage = $("#inputImage").val();
            if (!inputImage) {
                msgAlert("请上传图片")
                return;
            }
            ajaxJson("/admin/material/ajax/save",$("#form").serialize(),function(res){
                if(res.status){
                    location.href="/admin/material/list";
                }
            })
        })

        //上传图片
        uploadImg("#uploadImgBtn", "exam", function (data) {
            $("#imgImage").attr("src", data.url);
            $("#imgImage").parent().removeClass("hidden");
            $("#inputImage").val(data.uri);
        })
    </script>
</head>
<body>
<ol class="breadcrumb">
    <li><a th:href="@{/admin/material/list}">图片列表</a></li>
    <li class="active"th:text="${data}?'修改图片':_">添加图片</li>
</ol>
<form class="form-horizontal" id="form">
    <input type="hidden" name="id" th:if="${data}" th:value="${data.id}" id="id">
    <input type="hidden" name="imageUrl" id="inputImage" th:value="${data}?${data.imageUrl}">
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>图片名称</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <input type="text" class="form-control" placeholder="图片名称" name="name" id="name" th:value="${data}?${data.name}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>封面图片</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <button type="button" class="btn btn-default" id="uploadImgBtn">上传图片</button>
            <div class="fyl-mt10" th:classappend="${data}==null?'hidden'">
                <img th:src="${data}?${frdn}+${data.imageUrl}" id="imgImage" class="img-thumbnail">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-3 col-sm-8 col-md-8 col-lg-6">
            <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
            <button type="button" class="btn btn-warning backBtn">返回</button>
        </div>
    </div>
</form>
</body>
</html>